package cn.edu.suda.schoolBus.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.edu.suda.schoolBus.bean.Appointment;
import cn.edu.suda.schoolBus.service.AppointmentService;
import cn.edu.suda.schoolBus.util.ResultUtil;

@Controller
public class AppointmentController {

	@Autowired
	private AppointmentService appointmentService;

	@RequestMapping("/client/addAppointmentInfo")
	@ResponseBody
	public Map<String, Boolean> addAppointmentInfo(Appointment appointment) {
		return ResultUtil.getResult(appointmentService.addAppointment(appointment));
	}

	@RequestMapping("/client/cancelAppointmentInfo")
	@ResponseBody
	public Map<String, Boolean> cancelAppointmentInfo(@RequestParam("relateToDynamicCarNumber") int aId) {
		return ResultUtil.getResult(appointmentService.cancelAppointment(aId));
	}

	@RequestMapping("/client/getAppointment")
	@ResponseBody
	public Map<String, Boolean> getAppointment(int pId, int dcnId) {
		int i = 0;
		if (appointmentService.getAppointment(pId, dcnId) != null) {
			i = 1;
		}
		return ResultUtil.getResult(i);
	}

	@RequestMapping("/client/getAppointmentDcnId")
	@ResponseBody
	public int getAppointmentDcnId(int aId) {
		return appointmentService.getAppointment(aId).getRelateToDynamicCarNumber();
	}

	@RequestMapping("/client/getAppointmentInfo")
	@ResponseBody
	public List<Appointment> getAppointmentInfo(int pId, int aStatus, int dcnStatus) {
		return appointmentService.getAppointmentInfo(pId, aStatus, dcnStatus);
	}

}
